package ioliu;

import java.io.*;
import java.nio.charset.MalformedInputException;


//覆盖写入
public class Demo03 {
    public static void main(String[] args) {

        String s1="";
        BufferedReader br =null;
        BufferedWriter bw =null;
        try {

            File file = new File("E:\\stream\\a.txt");
            File file1 = new File("E:\\stream");
            if(!file1.exists()){
                file1.mkdirs();
            }
            String s;

           br = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
           bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file1+"\\ f.txt" )));
            while((s = br.readLine())!=null){

                //覆盖写入
                bw.write(s+System.getProperty("line.separator"));  //   System.getProperty("line.separator")相当于 加了一个换行符"\r\n"
                bw.flush();

                s1+= s.toString()+System.getProperty("line.separator");//当前系统的换行符windows是\r\n,unix是\n
            }
            bw.close();
            br.close();
        } catch (Exception e) {
            e.printStackTrace();
        }


        System.out.println(s1);

    }

}
